package com.ruoyi.edit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edit.domain.GrowthObservation;
import com.ruoyi.edit.service.IGrowthObservationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成长观察Controller
 * 
 * @author qiufeng
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/system/growthObservation")
public class GrowthObservationController extends BaseController
{
    private String prefix = "system/growthObservation";

    @Autowired
    private IGrowthObservationService growthObservationService;

    @GetMapping()
    public String growthObservation()
    {
        return prefix + "/growthObservation";
    }

    /**
     * 查询成长观察列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GrowthObservation growthObservation)
    {
        startPage();
        List<GrowthObservation> list = growthObservationService.selectGrowthObservationList(growthObservation);
        return getDataTable(list);
    }

    /**
     * 导出成长观察列表
     */
    @Log(title = "成长观察", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GrowthObservation growthObservation)
    {
        List<GrowthObservation> list = growthObservationService.selectGrowthObservationList(growthObservation);
        ExcelUtil<GrowthObservation> util = new ExcelUtil<GrowthObservation>(GrowthObservation.class);
        return util.exportExcel(list, "成长观察数据");
    }

    /**
     * 新增成长观察
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存成长观察
     */
    @Log(title = "成长观察", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GrowthObservation growthObservation)
    {
        return toAjax(growthObservationService.insertGrowthObservation(growthObservation));
    }

    /**
     * 修改成长观察
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GrowthObservation growthObservation = growthObservationService.selectGrowthObservationById(id);
        mmap.put("growthObservation", growthObservation);
        return prefix + "/edit";
    }

    /**
     * 修改保存成长观察
     */
    @Log(title = "成长观察", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GrowthObservation growthObservation)
    {
        return toAjax(growthObservationService.updateGrowthObservation(growthObservation));
    }

    /**
     * 删除成长观察
     */
    @Log(title = "成长观察", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(growthObservationService.deleteGrowthObservationByIds(ids));
    }
}
